# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lapack

pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.8.0
pkgrel=1
arch=('any')
pkgdesc="Linear Algebra PACKage (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc-fortran")
options=('strip' 'staticlibs')
license=('LGPL')
url="http://www.netlib.org/lapack"
source=("http://www.netlib.org/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('deb22cc4a6120bff72621155a9917f485f96ef8319ac074a7afbc68aab88bcf6')

build() {
  cd "$srcdir"
  mkdir -p build-${CARCH} && cd build-${CARCH}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G"MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_Fortran_COMPILER=${MINGW_PREFIX}/bin/gfortran.exe \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_NEED_RESPONSE=ON \
      -DBUILD_TESTING=OFF \
      ../${_realname}-${pkgver}
  make

  cd "$srcdir"
  mkdir -p build-${CARCH}s && cd build-${CARCH}s
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G"MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_Fortran_COMPILER=${MINGW_PREFIX}/bin/gfortran.exe \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -DBUILD_TESTING=OFF \
      ../${_realname}-${pkgver}
  make
}

package() {
  cd "$srcdir/build-${CARCH}s"
  make DESTDIR="$pkgdir" install
  cd "$srcdir/build-${CARCH}"
  make DESTDIR="$pkgdir" install
}
